package edu.uta.cfl.engine;

import java.util.ArrayList;

import edu.uta.cfl.data.Component;
import edu.uta.cfl.data.Parameter;

public class TestCaseManager {

	public static double getFailTCSpc(int[] tc, ArrayList<Component> spcCmps,
			ArrayList<Parameter> prms) {
		double tcSpc = 0;
		for (Component cmp : (ComboManager.getCombo(tc, prms)).getComponent()) {
			int idx = ComponentManager.idxCmpLst(cmp, spcCmps);
			if (idx != -1)
				tcSpc += (spcCmps.get(idx)).getRankValue();
		}
		return tcSpc;
	}

	public static boolean isTCExist(int[] tc, ArrayList<int[]> ts) {
		if (ts.size() == 0)
			return false;
		if (frequency(tc, ts) > 0)
			return true;
		return false;
	}

	public static int frequency(int[] tc, ArrayList<int[]> ts) {
		int fr = 0;
		for (int[] testCase : ts) {
			if (equals(tc, testCase))
				fr++;
		}
		return fr;

	}

	public static boolean equals(int[] firstTC, int[] secondTC) {
		int match = 0;
		for (int i = 0; i < firstTC.length; i++)
			if (firstTC[i] == secondTC[i])
				match++;
		if (match == firstTC.length)
			return true;
		return false;
	}

	public static int firstOccurrence(int[] tc, ArrayList<int[]> ts) {
		for (int i = 0; i < ts.size(); i++) {
			if (equals(tc, ts.get(i)))
				return i;
		}
		return -1;
	}
}
